<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div class="con">
        
    </div>
</body>
<script>
    let con = document.querySelector('.con');
    let btn = document.createElement('button');
    let intervalid;
    let count = 10;

    btn.innerHTML = '开始';
    btn.onclick = function() {
        if(intervalid) {
            clearInterval(intervalid);
            intervalid = '';
        }else{
            intervalid = setInterval(() => {
                btn.innerHTML = count--;
            },1000)
        }
    }

    con.appendChild(btn);
</script>
</html>